package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sc.nft.enums.PayChannelEnum;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.UserBankCard;
import com.sc.nft.mapper.UserBankCardMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 用户银行卡表(sc_user_bank_card)数据DAO
 *
 * @author kancy
 * @since 2022-08-31 00:56:48
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class UserBankCardDao extends ServiceImpl<UserBankCardMapper, UserBankCard> {

    public List<UserBankCard> getByUserId(Long userId){
        LambdaQueryWrapper<UserBankCard> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserBankCard::getUserId,userId);
        return list(wrapper);
    }
    public List<UserBankCard> getByUserIdAndChannel(Long userId, PayChannelEnum channel){
        LambdaQueryWrapper<UserBankCard> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserBankCard::getUserId,userId);
        wrapper.eq(UserBankCard::getChannel,channel);
        return list(wrapper);
    }
    public UserBankCard getByUserIdAndChannelAndCardNo(Long userId, PayChannelEnum channel,String bankCardNo){
        LambdaQueryWrapper<UserBankCard> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserBankCard::getUserId,userId);
        wrapper.eq(UserBankCard::getChannel,channel);
        wrapper.eq(UserBankCard::getBankCardNo,bankCardNo);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }
    public Integer getCountByUserId(Long userId) {
        LambdaQueryWrapper<UserBankCard> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserBankCard::getUserId,userId);
        return count(wrapper);
    }


    public UserBankCard getFirstCard(Long userId,PayChannelEnum channel) {
        LambdaQueryWrapper<UserBankCard> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserBankCard::getUserId,userId);
        wrapper.eq(UserBankCard::getChannel,channel);
        wrapper.orderByAsc(UserBankCard::getId);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }

    public UserBankCard getByBindId(Long bindId){
        return lambdaQuery().eq(UserBankCard::getBindId,bindId).one();
    }

}